package com.example.zdxk.Decoder;


import com.example.zdxk.util.FormatUtil;

public class SendDecoder {

     public static byte[] toData(byte[] id, byte[] imei, byte[] content){
         byte[] data;
         if(null != content) data=new byte[19+content.length];
         else data=new byte[19];

         byte[] sync = {(byte)0x24,(byte)0x5A,(byte)0x44};						//同步头
         byte prop = (byte)0x00;													//属性
         byte version_num = (byte)0x01;											//版本号
         byte mes_body_termi = (byte)0x23;										//消息体结束符
         byte check = (byte)0x00;												//校验码
         byte[] mes_termi = {(byte)0x0D,(byte)0x0A};								//消息结束符

         System.arraycopy(sync,0,data,0,3);
         System.arraycopy(id,0,data,3,2);
         data[5] = prop;

         System.arraycopy(imei,0,data,6,8);
         data[14] = version_num;                                                //消息体之前

         if(null != content) System.arraycopy(content,0,data,15,content.length);       //消息体

         data[data.length-4] = mes_body_termi;
         System.arraycopy(mes_termi,0,data,data.length-2,2);

         byte[] temp = new byte[data.length-3];
         System.arraycopy(data,0,temp,0,data.length-3);
         check = FormatUtil.getXor(temp);							//得出校验码
         data[data.length-3] = check;

         return data;
    }
}
